var e = getApp();

Page({
    data: {
        codeId: null,
        codeKey: null,
        codeInfo: null,
        codeLevelDescription: ""
    },
    onLoad: function(e) {
        var d = this;
        if (e.key) this.setData({
            codeKey: e.key
        }, function() {
            d.getCodeDetailsByKey();
        }); else {
            if (!e.code_id) return void wx.showToast({
                title: "升级码不存在",
                icon: "none",
                duration: 1500,
                success: function(e) {
                    wx.redirectTo({
                        url: "/packageH/member/upgrade_code/index/index"
                    });
                }
            });
            this.setData({
                codeId: e.code_id
            }, function() {
                d.getCodeDetails();
            });
        }
        wx.setNavigationBarTitle({
            title: "升级码"
        });
    },
    onPullDownRefresh: function() {
        this.data.codeKey ? this.getCodeDetailsByKey() : this.getCodeDetails();
    },
    onShareAppMessage: function() {
        var e = "升级码 " + this.data.codeInfo.code.member_level.level_name;
        return this.data.codeInfo.code.dividend_level && (e += " + " + this.data.codeInfo.code.dividend_level.level_name), 
        {
            title: e,
            path: "/packageH/member/upgrade_code/group_details/group_details?key=" + this.data.codeInfo.code.key
        };
    },
    onShareTimeline: function() {
        var e = "升级码 " + this.data.codeInfo.code.member_level.level_name;
        return this.data.codeInfo.code.dividend_level && (e += " + " + this.data.codeInfo.code.dividend_level.level_name), 
        {
            title: e,
            path: "/packageH/member/upgrade_code/group_details/group_details?key=" + this.data.codeInfo.code.key
        };
    },
    getCodeDetails: function() {
        var d = this;
        wx.showLoading({
            title: "加载中",
            mask: !0
        });
        var o = e.getNetAddresss("plugin.upgrade-code.Frontend.controllers.code.index");
        e._getNetWork({
            url: o,
            data: {
                id: this.data.codeId
            },
            success: function(e) {
                var o = e.data, t = o.data, a = o.result, i = o.msg;
                if (wx.stopPullDownRefresh(), 0 === a) return wx.hideLoading(), void wx.showToast({
                    title: i,
                    duration: 1500,
                    mask: !1,
                    icon: "none",
                    success: function(e) {
                        wx.redirectTo({
                            url: "/packageH/member/upgrade_code/index/index"
                        });
                    }
                });
                var n = "";
                t.code.member_level && t.code.dividend_level ? n = t.code.member_level.level_name + " + " + t.code.dividend_level.level_name : t.code.member_level ? n = t.code.member_level.level_name : t.code.dividend_level && (n = t.code.dividend_level.level_name), 
                d.setData({
                    codeInfo: t,
                    codeLevelDescription: n
                }), wx.hideLoading();
            }
        });
    },
    getCodeDetailsByKey: function() {
        var d = this;
        wx.showLoading({
            title: "加载中",
            mask: !0
        });
        var o = e.getNetAddresss("plugin.upgrade-code.Frontend.controllers.code.share");
        e._getNetWork({
            url: o,
            data: {
                key: this.data.codeKey
            },
            success: function(e) {
                var o = e.data, t = o.data, a = o.result, i = o.msg;
                if (wx.stopPullDownRefresh(), 0 === a) return wx.hideLoading(), void wx.showToast({
                    title: i,
                    duration: 1500,
                    mask: !1,
                    success: function(e) {
                        wx.navigateBack({
                            delta: 1
                        });
                    }
                });
                var n = t.code.member_level.level_name;
                t.code.dividend_level && (n += " + " + t.code.dividend_level.level_name), d.setData({
                    codeInfo: t,
                    codeLevelDescription: n
                }), wx.hideLoading();
            }
        });
    }
});